package com.mark.mall.web.platform.config;

import lombok.RequiredArgsConstructor;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

/**
 * @author admin
 */
@Configuration
@RequiredArgsConstructor
public class RestClientConfig extends AbstractElasticsearchConfiguration {
    private final ElasticSearchConfiguration elasticSearchConfiguration;
    @Override
    public RestHighLevelClient elasticsearchClient() {
        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo(elasticSearchConfiguration.getUris())
                .build();
        return RestClients.create(clientConfiguration).rest();
    }
}
